<% layout('/layouts/default.html', {title: '站修线倒车通知单查询', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('站修线倒车通知单查询')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tblXdZxxdctzd}" action="${ctx}/tbl/lineform/tblXdZxxdctzd/listData2" method="post" class="form-inline"
			data-page-no="${parameter.pageNo}" data-page-size="10000" data-order-by="${parameter.orderBy}">

			<div class="form-group">
				<label class="control-label">${text('开始时间')}：</label>
				<div class="control-inline">
					<#form:input path="startTime" maxlength="20" class="form-control laydate" style="width:180px !important"
					dataFormat="date" data-type="datetime" autocomplete="off" data-format="yyyy-MM-dd HH:mm:ss" id="startTime" />
				</div>
			</div>

			<div class="form-group">
				<label class="control-label">${text('结束时间')}：</label>
				<div class="control-inline">
					<#form:input path="endTime" maxlength="20" class="form-control laydate" style="width:180px !important"
					dataFormat="date" data-type="datetime" autocomplete="off" data-format="yyyy-MM-dd HH:mm:ss" id="endTime" />
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('车号')}：</label>
				<div class="control-inline">
					<#form:input path="wagonno" maxlength="20" class="form-control width-120"/>
				</div>
			</div>
<!--			<div class="form-group">-->
<!--				<label class="control-label">${text('站修类型')}：</label>-->
<!--				<div class="control-inline width-120">-->
<!--					<% var items = [{label:'大修',value:'1'},{label:'中修',value:'2'},{label:'定修',value:'3'},{label:'整修',value:'4'}]; %>-->
<!--					<#form:select path="vehicleRepairStatus" blankOption="true" items="${items}" itemLabel="label" itemValue="value" class="form-control"/>-->
<!--				</div>-->
<!--			</div>-->
			<div class="form-group">
				<label class="control-label">${text('车站')}：</label>
				<div class="control-inline width-120">
					<#form:select path="dqczbh" maxlength="2" blankOption="true" items="${lineList}" itemLabel="stationName" itemValue="stationCode" class="form-control" onchange="stationChange()"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('倒出线路')}：</label>
				<div class="control-inline width-120">
					<#form:select path="dqxlbh" maxlength="50" items="${lineListByStation}" itemLabel="" itemValue="lineCode" class="form-control" />
				</div>
			</div>
			<div class="form-group">
				<div class="control-inline">
					<#form:checkbox id="deviceNo" path="deviceNo" dictType="all_line" class="form-control" />
				</div>
			</div>
			<div class="form-group">

				<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
				<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
<!--				<a onclick="addBtn()" class="btn btn-primary btn-sm">${text('新增')}</a>-->
<!--				<button onclick="delBtn()" class="btn btn-primary btn-sm">${text('删除')}</button>-->
<!--				<button onclick="confirmBtn()" class="btn btn-primary btn-sm">${text('确认')}</button>-->
<!--				<button onclick="cancelBtn()" class="btn btn-primary btn-sm">${text('撤销')}</button>-->
			</div>
		</#form:form>
		<table id="dataGrid"></table>
<!--		<div id="dataGridPage"></div>-->
	</div>
</div>
</div>
<% } %>
<script>
	document.getElementById('startTime').addEventListener('change', validateTimes);
	document.getElementById('endTime').addEventListener('change', validateTimes);

	function validateTimes() {

		const startTime = new Date(document.getElementById('startTime').value);
		const endTime = new Date(document.getElementById('endTime').value);

		console.log(startTime,endTime,"1234567879")

		if (startTime > endTime) {
			alert('开始时间不能大于结束时间');
			document.getElementById('startTime').value = ''; // 清空开始时间
		}
	}
	$(function(){
		// 定义一个函数来更新班次和日期
		function updateShiftAndTime() {
			var $startTime = $("#startTime");
			var $endTime = $("#endTime");
			var date_now = new Date();
			var hours = date_now.getHours(); //获取小时

			var startyear = date_now.getFullYear();  // 获取年
			var endyear = date_now.getFullYear();  // 获取年
			var startmonth = date_now.getMonth() + 1;  // 获取月
			var endmonth = date_now.getMonth() + 1;  // 获取月

			var startDay = date_now.getDate();
			var endDay = date_now.getDate();

			var startNow = '08:00:00'
			var endNow = '19:00:00'

			//设置时间回显
			if (hours >= 19) {
				// 夜班 (19:00到0:00)，开始日期不变 时间改为19：00：00 结束日期加一 时间为08：00：00
				date_now.setDate(date_now.getDate() + 1);// 日期加一天
				endDay = date_now.getDate();  // 更新日
				endmonth = date_now.getMonth() + 1;  // 更新月
				endyear = date_now.getFullYear();  // 更新年
				startNow = '19:00:00'
				endNow = '08:00:00'
			} else if (hours < 8) {
				// 夜班 (0:00到8:00)，开始日期减一 时间为19：00：00 结束日期不变 时间为 08：00：00
				date_now.setDate(date_now.getDate() - 1); // 日期减去一天
				startDay = date_now.getDate();  // 更新日
				startmonth = date_now.getMonth() + 1;  // 更新月
				startyear = date_now.getFullYear();  // 更新年
				startNow = '19:00:00'
				endNow = '08:00:00'
			} else {
				// 白班 (8:00到19:00) 开始日期不变 时间为08：00：00 结束日期不变 时间为19：00：00
			}
			// 设置日期，补零处理
			$startTime.val(startyear + "-" + (startmonth < 10 ? '0' + startmonth : startmonth) + "-" + (startDay < 10 ? '0' + startDay : startDay) + " " + startNow);
			$endTime.val(endyear + "-" + (endmonth < 10 ? '0' + endmonth : endmonth) + "-" + (endDay < 10 ? '0' + endDay : endDay) + " " + endNow);
		}

		// 页面加载时更新一次
		updateShiftAndTime();

		// 每隔一分钟更新一次班次和日期
		// setInterval(updateShiftAndTime, 60000);
	});
	// 初始化DataGrid对象
	$('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		multiselect:true,
		rownumWidth:40,
		shrinkToFit:false,
		columnModel: [
			//{header:'${text("操作")}', name:'actions', align:"center", width:45, formatter: function(val, obj, row, act){
			//	var actions = [];
			//	if("0" == row.status) {
			//		actions.push('<a href="${ctx}/tbl/lineform/tblXdZxxdctzd/form?recId='+row.recId+'" class="btnList" title="${text("编辑站修线倒车通知单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
			//
			//		return actions.join('');
			//	}else{
			//		return actions.join('');
			//	}
			//}},
			{header:'${text("添加时间")}', name:'addTime', align:"center", index:'a.add_Time', width:180},
			{header:'${text("车号")}', name:'wagonno', index:'a.wagonno', width:100, align:"center", formatter: function(val, obj, row, act){
					return '<a href="${ctx}/tbl/lineform/tblXdZxxdctzd/form?recId='+row.recId+'" data-area="770px" class="btnList" data-title="${text("编辑站修线倒车通知单")}">'+(val||row.id)+'</a>';
				}},
			{header:'${text("设备号")}', name:'deviceNo', align:"center", index:'a.device_no', width:100},
			{header:'${text("当前车站")}', name:'dqczmc', align:"center", index:'a.dqczmc', width:80},
			{header:'${text("当前场地")}', name:'dqcdmc', align:"center", index:'a.dqcdmc', width:100},
			{header:'${text("当前线路")}', name:'dqxlmc', align:"center", index:'a.dqxlmc', width:120},
			{header:'${text("车组")}', name:'wagonGroupName', align:"center", index:'a.wagon_group_name', width:50},
			{header:'${text("是否出场")}', name:'isOutStage', align:"center", index:'a.is_out_stage', width:80, formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("")}', true);
				}},
			{header:'${text("去向")}', name:'destName', align:"center", index:'a.dest_name', width:60, formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('CLQX')}, val, '${text("")}', true);
				}},
			{header:'${text("是否禁峰")}', name:'isNopeak', align:"center", index:'a.is_nopeak', width:80, formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("")}', true);
				}},
			{header:'${text("出场状况")}', name:'cczk', align:"center", index:'a.cczk', width:80, formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('CCZK')}, val, '${text("")}', true);
				}},
			{header:'${text("专项整治")}', name:'zxzz', align:"center", index:'a.zxzz', width:80, formatter: function(val, obj, row, act){
					return js.getDictLabel(${@DictUtils.getDictListJson('ZXZZ')}, val, '${text("")}', true);
				}},
			{header:'${text("备注")}', name:'remark', align:"center", index:'a.remark', width:100},
			{header:'${text("列检调度")}', name:'ljddUsername', align:"center", index:'a.ljdd_username', width:100},
			{header:'${text("列检调度确认时间")}', name:'ljddConfirmTime', align:"center", index:'a.ljdd_confirm_time', width:180},
			{header:'${text("车站调度")}', name:'czddUsername', align:"center", index:'a.czdd_username', width:100},
			{header:'${text("车站调度确认时间")}', name:'czddConfirmTime', align:"center", index:'a.czdd_confirm_time', width:180},
		],

		// 表格初始化完成后执行
		complete: function(){
			console.log("表格初始化完成后执行")
		},

		// 加载成功后执行事件
		ajaxSuccess: function(data){

		}
	}).dataGrid('setLabel', 'rn', '序号');

	laydate.render({
		elem: '#ID-laydate-more-btns',
		btns: ['confirm']
	});
	function stationChange(){

		var params={"stationCode":$("#dqczbh").val()};//车站
		console.log($("#dqxlbh").val());
		$("#dqxlbh").empty();
		$("#dqxlbh").val("");
		var url = "${ctx}/tbl/replyform/tblXdJxchsd/getLineList";

		$("input[name='deviceNo']:checkbox").each(function(){

			if((this).checked == true)
			{
				url = "${ctx}/tbl/lineform/tblXdZxxdctzd/getAllLineList";
			}
		})

		$.post(url,params,function(data){
			console.log(222,data);
			//debugger;
			if(data.tblXdLjzyjlList.length!=1){
				$("#dqxlbh").append('<option value=""> </option>');
			}
			for(var key in data.tblXdLjzyjlList){
				var row=data.tblXdLjzyjlList[key];
				console.log(111,key);
				$("#dqxlbh").append('<option value="'+row.lineCode+'">'+row.line+'</option>');
			}
			//如果没有数据清空列表显示没有找到列表项
			if(data.tblXdLjzyjlList.length == 0){
				$("#dqxlbh").empty();
				$("#dqxlbh").val("");
			}
		},"json");
	};

	//复选框默认选择状态
	$('#deviceNo').iCheck('check');

	$('#deviceNo').on('ifChecked', function(){
		var params={"stationCode":$("#dqczbh").val()};//车站
		$("#dqxlbh").empty();
		$("#dqxlbh").val("");
		var url = "${ctx}/tbl/lineform/tblXdZxxdctzd/getAllLineList";
		$.post(url,params,function(data){
			console.log(222,data);
			//debugger;
			if(data.tblXdLjzyjlList.length!=1){
				$("#dqxlbh").append('<option value=""> </option>');
			}
			for(var key in data.tblXdLjzyjlList){
				var row=data.tblXdLjzyjlList[key];
				console.log(111,key);
				$("#dqxlbh").append('<option value="'+row.lineCode+'">'+row.line+'</option>');
			}
			//如果没有数据清空列表显示没有找到列表项
			if(data.tblXdLjzyjlList.length == 0){
				$("#dqxlbh").empty();
				$("#dqxlbh").val("");
			}
		},"json");
	});
	$('#deviceNo').on('ifUnchecked', function(){
		var params={"stationCode":$("#dqczbh").val()};//车站
		$("#dqxlbh").empty();
		$("#dqxlbh").val("");
		var url = "${ctx}/tbl/replyform/tblXdJxchsd/getLineList";
		$.post(url,params,function(data){
			console.log(222,data);
			//debugger;
			if(data.tblXdLjzyjlList.length!=1){
				$("#dqxlbh").append('<option value=""> </option>');
			}
			for(var key in data.tblXdLjzyjlList){
				var row=data.tblXdLjzyjlList[key];
				console.log(111,key);
				$("#dqxlbh").append('<option value="'+row.lineCode+'">'+row.line+'</option>');
			}
			//如果没有数据清空列表显示没有找到列表项
			if(data.tblXdLjzyjlList.length == 0){
				$("#dqxlbh").empty();
				$("#dqxlbh").val("");
			}
		},"json");
	});
	function delBtn(){
		var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
		if(ids.length==0){
			js.showMessage('请选择要删除的记录。', '', 'warning', 4000);
			return;
		}else{
			var msg = "确定进行【删除】操作？";
			js.confirm(msg,function(data){
				var jhhString = "";//拼接字符串
				for(var i=0;i<ids.length;i++){
					jhhString += ","+ids[i];
				}
				console.log(jhhString);
				if(""!=jhhString) {
					jhhString=jhhString.substring(1);
				}
				console.log(jhhString);
				$.post("${ctx}/tbl/lineform/tblXdZxxdctzd/delete",{'jhhString':jhhString},function(e){
					if(e.result == "false"){
						js.showMessage(e.message, '', 'error', 4000);
					}else{
						js.showMessage('删除成功！', '', 'success', 4000);
					}
					$('#dataGrid').trigger("reloadGrid");
				},"json")
						.error(function(data, status, xhr){
							js.showMessage('删除失败！', '', 'error', 4000);
						});
			});
		}
	}

	//新增
	function addBtn(){
		var exportLine = $("#dqxlbh").val();
		if(exportLine == ""){
			js.showMessage('请选择导出线路！', '', 'warning', 4000);
			return;
		}
		$.post("${ctx}/tbl/lineform/tblXdZxxdctzd/insertData",{'dqxlbh':exportLine},function(e){},"json");
	}
	//确认
	function confirmBtn(){
		var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
		if(ids.length==0){
			js.showMessage('请选择要确认的记录。', '', 'warning', 4000);
			return;
		}else{
			var msg = "确定进行【确认】操作？";
			js.confirm(msg,function(data){
				var jhhString = "";//拼接字符串
				for(var i=0;i<ids.length;i++){
					jhhString += ","+ids[i];
				}
				console.log(jhhString);
				if(""!=jhhString) {
					jhhString=jhhString.substring(1);
				}
				console.log(jhhString);
				$.post("${ctx}/tbl/lineform/tblXdZxxdctzd/confirm",{'ids':jhhString},function(e){
					if(e.result == "false"){
						js.showMessage(e.message, '', 'error', 4000);
					}else{
						js.showMessage('确认成功！', '', 'success', 4000);
					}
					$('#dataGrid').trigger("reloadGrid");
				},"json")
						.error(function(data, status, xhr){
							js.showMessage('确认失败！', '', 'error', 4000);
						});
			});
		}
	}

	//撤销
	function cancelBtn(){
		var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
		if(ids.length==0){
			js.showMessage('请选择要撤销的记录。', '', 'warning', 4000);
			return;
		}else{
			var msg = "确定进行【撤销】操作？";
			js.confirm(msg,function(data){
				var jhhString = "";//拼接字符串
				for(var i=0;i<ids.length;i++){
					jhhString += ","+ids[i];
				}
				console.log(jhhString);
				if(""!=jhhString) {
					jhhString=jhhString.substring(1);
				}
				console.log(jhhString);
				$.post("${ctx}/tbl/lineform/tblXdZxxdctzd/cancel",{'ids':jhhString},function(e){
					if(e.result == "false"){
						js.showMessage(e.message, '', 'error', 4000);
					}else{
						js.showMessage('撤销成功！', '', 'success', 4000);
					}
					$('#dataGrid').trigger("reloadGrid");
				},"json")
						.error(function(data, status, xhr){
							js.showMessage('撤销失败！', '', 'error', 4000);
						});
			});
		}
	}

</script>
<style>
	.laydate-btns-clear{
		display: none !important;
	}
</style>